package com.shudai.largescreen.controller;

import com.shudai.largescreen.common.R;
import com.shudai.largescreen.pojo.vo.AreaAchievementVo;
import com.shudai.largescreen.pojo.vo.ReCustomerVo;
import com.shudai.largescreen.pojo.vo.RegionCity;
import com.shudai.largescreen.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/")
@Api(tags = "地区业绩看板",value = "地区业绩看板")
@RequiredArgsConstructor
public class RegionController {

    private final RegionService regionService;

    //全国经销商总额
    @PostMapping("/region-board/nation-total")
    @ApiOperation(value = "全国经销商总额")
    public R getAllRegionCity(){

        return R.ok( regionService.getAllRegionCity());
    }


    @PostMapping("/region-board/quests")
    @ApiOperation(value = "本周拜访任务/下单任务")
    public R getWeakRegionCity(String province,String region){
        //本周拜访任务
        RegionCity weakRegionCity = regionService.getWeakRegionCity(province, region);
        //本周下单任务
        RegionCity weakOrderCity = regionService.getWeakOrderCity(province, region);


        Map<String,RegionCity> map = new HashMap<>();
        map.put("visit",weakRegionCity);
        map.put("order",weakOrderCity);

        return R.ok( map);
    }


    @PostMapping("/region-board/area-achievement")
    @ApiOperation(value = "地区业绩总汇")
    public R getAreaAchievementCity(String province,String region,String teamName, String startTime ,String  status){
        System.out.println( "地区业绩总汇 province : " +province + " "+region);
        List<AreaAchievementVo>  areaAchievementCity = regionService.getAreaAchievementCity(province,region,teamName,startTime,status);
       Map<String,Object> map = new HashMap<>();
       map.put("chartData",areaAchievementCity);
        return R.ok(map);
    }



    @PostMapping("/region-board/re-customer")
    @ApiOperation(value = "超平均时未返单客户/已购未返单客户")
    public R getReCustomer(String province,String region){
        //超平均时未返单客户
//        RegionCity weakRegionCity = regionService.getReCustomers(area, district);
        //已购未返单客户
        List<ReCustomerVo> reCustomerVoList = regionService.getReCustomerIOrder(province, region);

        //超过平均时间未返单用户
        List<ReCustomerVo> CustomerVoList = regionService.getReCustomerTime(province, region);

        List<Map<String,Object>> pagingInfo = new ArrayList<>();


        Map<String,Object> objectMap = new HashMap<>();
        objectMap.put("title"," 已购未返单客户");
        objectMap.put("data",reCustomerVoList);
        Map<String,Object> map = new HashMap<>();
        map.put("title","超平均时未返单客户");
        map.put("data",CustomerVoList);


        pagingInfo.add(objectMap);
        pagingInfo.add(map);
        Map<String,List<Map<String,Object>>> map1 = new HashMap<>();
        map1.put("pagingInfo",pagingInfo);

        return R.ok( map1);
    }

    @PostMapping("/region-board/region-rank")
    @ApiOperation(value = "地区排名")
    public R getRegionRank(String province,String region){
        System.out.println("hausb"+province);
        return R.ok(regionService.getRegionRank(province,region));
    }



    @PostMapping("/region-board/conversion-rate")
    @ApiOperation(value = "经销商转化率")
    public R getConversionRate(String province,String region,String startData){

        return R.ok(regionService.getConversionRate(province,region,startData));
    }

    @ApiOperation("经销商等级总汇")
    @PostMapping(value = "/region-board/level-total")
    public R getCityOrder(String province, String region){
        return R.ok(regionService.getDistributorGrade( province,region));
    }

}
